package com.moon.service.impl;

import com.moon.annotations.DataSource;
import com.moon.mapper.EmpMapper;
import com.moon.pojo.JobOption;
import com.moon.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;


    @Override
    @DataSource("db02")
    public JobOption getEmpJobData() {
        List<Map<Object, Object>> maps = empMapper.countEmpJobData();

        List<Object> poses = maps.stream().map(map -> map.get("pos")).collect(Collectors.toList());
        List<Object> totals = maps.stream().map(map -> map.get("total")).collect(Collectors.toList());

        return new JobOption(poses, totals);
    }

    @Override
    @DataSource("db02")
    public List<Map<Object, Object>> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }
}
